@extends('layouts.header')
@section('title','短信设置')
@section('content')
<article class="page-container">
    <form class="form form-horizontal" id="form" autocomplete="off">
        <div class="row cl">
            <label class="form-label col-xs-3"><span class="c-red">*</span>短信提醒：</label>
            <input type="hidden" name="is_open" value="">
            <div class="formControls col-xs-9">
                <div id="mySwitch" class="switch" data-on-label="开" data-off-label="关">
                    <input type="checkbox" name="is_open" @if((isset($data['set']['is_open']) ? $data['set']['is_open'] :'') === 'on') checked @endif />
                </div>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3">剩余条数：</label>
            <div class="formControls col-xs-9">
                {{isset($data['set']['count']) ? $data['set']['count']: 0}}
                <a class="btn btn-primary radius ml-50" id="buySms">购买</a>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3">到期通知规则：</label>
            <div class="formControls col-xs-9">
                <div class="mt-5">
                    <p class="c-blue">通用：</p>
                    <p class="ml-20">
                        到期前<input min="0" type="number" class="input-text" name="gqj_notice_early_days" value="{{isset($data['set']['gqj_notice_early_days']) ? $data['set']['gqj_notice_early_days']: 0}}">天开始提醒，
                        <span class="ml-10">每 <input min="0" type="number" class="input-text" name="gqj_notice_loop_days" value="{{ isset($data['set']['gqj_notice_loop_days']) ? $data['set']['gqj_notice_loop_days']: 0}}">天通知一次， </span>
                        <span class="ml-10">到期后<input type="number" class="input-text" name="gqj_notice_delay_days" value="{{isset($data['set']['gqj_notice_delay_days']) ? $data['set']['gqj_notice_delay_days']: 0}}">天后不再通知 </span>
                        <br>
                        <small  class="c-red">注意：<i>如果只提醒一次，必须满足：间隔天数 >（提前天数+推迟天数）</i></small>
                    </p>
                </div>
                <div class="mt-5">
                    <p class="c-blue">特殊： <span class="btn btn-primary radius size-MINI" onclick="layer_show('添加工器具的通知规则','gqj/set')">添加</span> </p>
                    <p class="ml-20">
                        <table class="table table-border table-bordered table-bg table-hover table-responsive radius">
                           <thead class="text-c">
                           <th>工器具</th>
                           <th>标准</th>
                           <th>检验周期(年)</th>
                           <th>提前天数</th>
                           <th>间隔天数</th>
                           <th>后延天数</th>
                           <th>操作</th>
                           </thead>
                        <tbody class="text-c">
                        @foreach($data['gqj_set'] as $item)
                            <tr>
                                <td>{{$item->tool_name}}</td>
                                <td>{{$item->std_num}}</td>
                                <td>{{$item->cycle}}</td>
                                <td>{{$item->early_days}}</td>
                                <td>{{$item->loop_days}}</td>
                                <td>{{$item->delay_days}}</td>
                                <td>
                                    <span class="btn btn-primary radius size-MINI" onclick="del(this,{{$item->id}})">删除</span>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                    </p>
                </div>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3">工器具到期通知内容：</label>
            <div class="formControls col-xs-9">
                【{{config('constant.alidysms_sign') ?: '汇邦检测'}}】尊敬的 { 送检单位 } ，您有 { x } 件工器具的合格证即将到期，请及时进行复检！
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3">关于通知内容：</label>
            <div class="formControls col-xs-9">
                【】中是签名，{ } 中是变量，每个变量不能超过20字。
                <br>
                签名：最多12字。短信：67字/条，多出的部分按条累计，不足67字按一条计算。
                <br>
                购买短信请联系销售。
                <br>
                自定义通知内容请联系销售或技术。技术联系方式wx：15910683901
                <br>
                短信发送时间：统一在10点陆续发送
            </div>
        </div>
        @csrf

        <div class="row cl pt-20">
            <div class="col-xs-9 col-xs-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                <input class="btn btn-danger radius ml-15" type="button" value="&nbsp;&nbsp;取消&nbsp;&nbsp;" onclick="layer_close();">
            </div>
        </div>
    </form>
</article>

<script type="text/javascript">
    $('#buySms').on('click', function (event) {
        layer.msg('联系通过业务员购买！');
    })
    $(function () {

        var index2;
        $('.select2').select2();

        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#form").validate({
            rules: {
                wechat_notice_id: {
                    required: true
                },
                manager_id: {
                    required: true
                },
            },
            // onkeyup:false,
            // focusCleanup:false,
            success: "valid",
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    type: 'post',
                    url: "",//自己提交给自己可以不写url
                    beforeSend: function () {
                        //0.4透明度 白色遮罩
                        index2 = layer.load(2, {shade: [0.3, '#fff']});
                    },
                    complete: function () {
                        layer.close(index2);
                    },
                    success: function (data) {
                        //判断添加结果
                        if (data === '1') {
                            // parent.window.location.reload();//刷新
                            parent.layer.msg('设置成功!', {icon: 1, time: 2000});
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }
                        else {
                            layer.msg('请先修改数据!', {icon: 2, time: 2000});
                        }
                    },
                    error: function (data) {
                        ajax_error(data);
                    }
                });
            }
        });
    });
    function del(obj,id) {
        ajax('post','gqj/set',{id:id,method:'del'},delBak)
        function delBak(res) {
           if(res == 1){
               $(obj).closest('tr').remove();
           }
        }
    }
</script>
@endsection